#pragma once
#include <iostream>
#include <unistd.h>

#include <thread>
#include <string>
typedef void *(*fun_c)(void *);
class threadData
{
public:
    void *_args;//构造Thread对象时传递的参数args
    std::string _name;
};
class Thread
{
public:
    Thread(int num, fun_c callback, void *args)

        : _fun(callback)
    {
        char buffer[1024];
        snprintf(buffer, sizeof(buffer) - 1, "%s-%d", "thread", num);
        _name = buffer;
        _tdData._args = args;
        _tdData._name = _name;
    }
    void start()//创建线程
    {
        pthread_create(&_tid,nullptr,_fun,(void*)&_tdData);
    }
    void join()//线程等待
    {
        pthread_join(_tid,nullptr);
    }
    std::string getName()
    {
        return _name;
    }
   ~Thread()
   {

   }

private:
    std::string _name;
    fun_c _fun;
    threadData _tdData;
    pthread_t _tid;
};